Add state new usage for following example.#5
Add state new usage for following example.#5zw963 wants to merge 1 commit intoruby-hyperloop:masterfrom
Conversation
Personal think following more intuitive for a declare statement like syntax. e.g. state :state_name, 'initial value' state :state_name, 'initial value', class: true
catmando
left a comment
There was a problem hiding this comment.
if you add some test cases you will see that this does not always work.
All these cases should work:
state :foo # will be initialized to nil
state foo: 12 # will be initialized to 12
state :foo, 12 # will be initialized to 12 also
state foo: 12, scope: :class
state :foo, 12, scope: :class
state :foo, {} # foo is initialized to nil, and there are no options
state :foo, {}, {} # foo is initialized to {} and there are no optionsThe thing that makes it tricky is that the last 2 cases.
Advice is to write test cases now...
|
Lets keep the discussion on this change here (rather than in the gitter chat) There is too much code out in the wild depending on the current structure to change it. Besides I think most dev's find the structure natural. Finally as far as initialization to nil, this is standard ruby. State variables are just like instance variables that cause rerendering when changed. Instance variables by default initialize to nil, and so do state variables. So I am fine with adding your syntax, but you are going to have to parse it so that both old and new style work. |
|
@catmando , Thanks for reply. After read some post write by you in quora, and Comparing-Redux-with-Hyperloop, I think current usage not so unreasonable. Though I still hope add new state usage to project, But, as I say previous in gitter, current, state :one_hash_state, scope: class, reader: all
state :one_hash_state, {scope: class}, scope: class # {scope: class} is state default value |
Personal think following more intuitive for a declare statement like syntax.
e.g.
state :state_name, 'initial value'
state :state_name, 'initial value', class: true